import { defineStore } from "pinia";
import { reactive } from "vue";
import { login } from '@/api/user'

export const useUserStore = defineStore('user', {
    state: () => ({
        loginStatus: 'logout', //login 或者 logout
        token: '',
    }),
    getters: {

        getToken: (state) => {
          return state.token;
        },
      },
    actions: {

        login(userName, pass,timeout=300) {

            // return login(userName, pass).then((resp) => {
            //     console.log(resp);
            //     if (resp.access.length > 0) {
            //         setTimeout(() => {
            //             this.loginStatus = 'login'
            //             this.token = resp.access
            //             localStorage.setItem('token', resp.access)
            //         }, timeout);

            //         return true
            //     } else {
            //         return false
            //     }
            // })
        },

        logout() {
            console.log('----logout----');
            this.loginStatus = 'logout'
            this.token = ''
            localStorage.removeItem('token')
        }
    }

})